import { Injectable } from '@angular/core';
import { config, Observable } from 'rxjs';

import { JsonPatchData } from '@app/core/domain/json-patch-data';
import { RequestParams } from '@app/core/domain/request-params';

import { BaseHttpService, PageItem } from '../base-http.service';
import { BaseService } from '../base.service';

export interface AdminUser {
  id: number;
  username: string;
  password: string;
  avatar: string;
  isadmin: boolean;
  deleted: boolean;
  addtime: Date;
  deactivated: boolean;
  email: string;
  city: number;
  province: number;
  description: string;
  userroles?: UserRole[];
  roleids: number;
  rolenames?: string;
  schoolid?: number;
  phone: string;
  lastlogintime: Date;
  deptids: number[];
}

export interface UserRole {
  id: number;
  rolename: string;
}

@Injectable({
  providedIn: 'root'
})
export class AdminUserService extends BaseService<AdminUser> {
  constructor() {
    super();
    this.apiPrefix = 'adminuser';
  }

  public register(adminUser: Partial<AdminUser>): Observable<AdminUser> {
    return this.http.post<AdminUser>(`/${this.apiPrefix}/register`, adminUser, { showLoading: true, needSuccessInfo: true });
  }

  public existUserName(userName: string): Observable<boolean> {
    return this.http.get(`/${this.apiPrefix}/ExistUserName?userName=${userName}`, {});
  }

  public existPhone(phone: string): Observable<boolean> {
    return this.http.get(`/${this.apiPrefix}/ExistPhone?phone=${phone}`, {});
  }

  public existEmail(email: string): Observable<boolean> {
    return this.http.get(`/${this.apiPrefix}/ExistEmail?email=${email}`, {});
  }
}
